import axios from 'axios';

// 创建 Axios 实例并设置 baseURL
const staffAxios = axios.create({
    baseURL: process.env.VUE_APP_BACKEND_URL + '/staff'
});

const albumAxios = axios.create({
    baseURL: process.env.VUE_APP_BACKEND_URL + '/album'
});

const photosAxios = axios.create({
    baseURL: process.env.VUE_APP_BACKEND_URL + '/photos'
});

const themeAxios = axios.create({
    baseURL: process.env.VUE_APP_BACKEND_URL + '/theme'
});

const uploadAxios = axios.create({
    baseURL: process.env.VUE_APP_BACKEND_URL + '/upload'
});


const backgroundAxios = axios.create({
    baseURL: process.env.VUE_APP_BACKEND_URL + '/background'
});



// 员工相关api
const staffApi = {
    // 员工登录
    async login(staff) {
        return staffAxios.post('/login', staff);
    }
};

// 主页背景api
const backgroundApi = {
    async findById() {
        return backgroundAxios.get('/findById');
    },

    async changeBackground(background) {
        return backgroundAxios.post('/changeBackground', background);
    }
};

//相册相关pai
const albumApi = {
    //分页查询
    async queryPage(currentPage, pageSize, queryCondition) {
        // 构造查询参数
        const params = {
            currentPage: currentPage,
            pageSize: pageSize,
            ...queryCondition
        };

        // 发送 GET 请求
        return albumAxios.get('/queryPage', { params: params });
    },
    //根据主题id查询相册
    async queryByThemeId(themeId) {
        return albumAxios.get('/queryByThemeId', { params: { themeId } });
    },
    //修改相册状态
    async updateStatus(id, status) {
        return albumAxios.post('/updateStatus', {
            id: id,
            status: status
        });
    },
    async addAlbum(album) {
        return albumAxios.post('/addAlbum', album);
    },

    async sameAlbumName(album) {
        return albumAxios.post('/sameAlbumName', album);
    },
    //根据id查询相册
    async queryById(albumId) {
        return albumAxios.get('/queryById', { params: { albumId } });
    },
    //修改相册信息
    async updateAlbum(album) {
        return albumAxios.post('/updateAlbum', album);
    },

    async addPhotos(album) {
        return albumAxios.post('/addPhotos', album);
    },

    async queryAll() {
        // 发送 GET 请求
        return albumAxios.get('/queryAll');
    },

    async queryByName(name) {
        // 发送 GET 请求
        return albumAxios.get('/queryByName', { params: { name } });
    },

    async changeShow(flag) {
        return albumAxios.get('/changeShow', { params: { flag } });
    },
};

//主题相关pai
const themeApi = {
    async queryAll(type) {
        // 发送 GET 请求
        return themeAxios.get('/queryAll', { params: { type } });
    },
    //分页查询
    async queryPage(currentPage, pageSize) {
        // 构造查询参数
        const params = {
            currentPage: currentPage,
            pageSize: pageSize,
        };

        // 发送 GET 请求
        return themeAxios.get('/queryPage', { params: params });
    },
    //根据id查询主题
    async queryById(id) {
        return themeAxios.get('/queryById', { params: { id } });
    },

    async sameThemeName(theme) {
        return themeAxios.post('/sameThemeName', theme);
    },

    async addTheme(theme) {
        return themeAxios.post('/addTheme', theme);
    },

    //修改主题信息
    async updateTheme(theme) {
        return themeAxios.post('/updateTheme', theme);
    },

    async deleteById(id) {
        return themeAxios.delete(`/deleteById/${id}`);
    },

    //修改主题状态
    async updateStatus(id, status) {
        return themeAxios.post('/updateStatus', {
            id: id,
            status: status
        });
    }
};

//上传相关pai
const uploadApi = {
    //上传相册
    async uploadPhotos(file, folderName) {
        const formData = new FormData();
        formData.append('file', file);
        formData.append('folderName', folderName)
        // 发送 POST 请求
        return uploadAxios.post('/photos', formData, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        });
    }
};

//照片相关pai
const photosApi = {
    //根据相册id查询照片
    async queryByAlbumId(albumId) {
        return photosAxios.get('/queryByAlbumId', { params: { albumId } });
    },

    //分页查询照片
    async queryPage(currentPage, pageSize, queryCondition) {
        // 构造查询参数
        const params = {
            currentPage: currentPage,
            pageSize: pageSize,
            ...queryCondition
        };

        // 发送 GET 请求
        return photosAxios.get('/queryPage', { params: params });
    },

    //根据相册id查询照片
    async deleteByIds(ids) {
        return photosAxios.post('/deleteByIds', ids);
    },

    //根据id查询照片信息
    async queryById(id) {
        return photosAxios.get('/queryById', { params: { id } });
    },

    async updatePhotos(photos) {
        return photosAxios.post('/updatePhotos', photos);
    },
};
export { staffApi, albumApi, themeApi, uploadApi, photosApi, backgroundApi };